<template>
	<view>
		<view class="bg-white">
			<view class="flex">
				<view v-if="likes" class="video-margin-number bg-white radius" @click="likesTap">
					<text class="lg text-red cuIcon-likefill"> </text> 已收藏
				</view>
				<view v-else class="video-margin-number bg-white radius" @click="likesTap">
					<text class="lg text-red cuIcon-like"> </text> 收藏
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		props: {
			item: {
				type: String,
				default: ''
			},
			like: {
				type: Boolean,
				default: false
			},
			types: {
				type: String,
				default: ''
			}
		},
		name:"like",
		data() {
			return {
				likes: true
			};
		},
		watch: {
			item(newVal) {
				this.likes = this.like
			}
		},
		created() {
			this.likes = this.like
		},
		computed:{
			...mapState(['userinfo'])
		},
		methods: {
			likesTap() {
				this.likes = !this.likes
				this.setUpdatelikes()
			},
			setUpdatelikes() {
				uni.showLoading()
				this.$api.update_like({
					user_id: this.userinfo._id,
					acticle_id: this.item
				}).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: this.likes?'收藏成功':'取消收藏',
						icon: 'none'
					})
					uni.$emit('update_list', this.item)
				}).catch(()=>{
					uni.hideLoading()
				})
			}
			
		}
	}
</script>

<style>
	.video-margin-number {
		font-size: 11px;
		margin: 0px 3px 3px 5px;
	}
</style>
